package com.sjg.sys.controller;

import com.sjg.sys.entity.SysOrganization;
import com.sjg.sys.entity.SysResources;
import com.sjg.sys.entity.SysReturnInfo;
import com.sjg.sys.service.SysOrganizationService;
import com.sjg.sys.utils.CommUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by fuqingjian on 2017/4/30.
 */
@Controller
@RequestMapping("org")
public class SysOrganizationController {
    @Resource
    private SysOrganizationService sysOrganizationService;
    @RequestMapping("index")
    public String index(){
        return "orgUserRoles";
    }
    @RequestMapping("addOrgIndex")
    public String addOrgIndex(){
        return "addOrg";
    }

    /**
     * 新增或更新
     * @param organization
     * @return
     */
    @RequestMapping("addOrUpdOrg")
    @ResponseBody
    public SysReturnInfo addOrUpdOrg(SysOrganization organization){
        if(organization.getId()==null){
            sysOrganizationService.insertSelective(organization);
            return CommUtil.rtnmsg(true,"新增成功");
        }else{
            sysOrganizationService.update(organization);
            return CommUtil.rtnmsg(true,"修改成功");
        }
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping("removeOrg")
    @ResponseBody
    public SysReturnInfo removeOrg(Long id){
        int num=sysOrganizationService.delete(id);
        return CommUtil.rtnmsg(true,"删除"+num+"条数据");
    }

    /**
     * 查询列表数据
     * @param organization
     * @return
     */
    @RequestMapping("queryOrgLists")
    @ResponseBody
    public SysReturnInfo queryOrgLists(SysOrganization organization){
        List<SysOrganization> organizationList=sysOrganizationService.selectbyOrganization(organization);
        return CommUtil.rtnmsg(true,"查询成功",organizationList);
    }
}
